<?php echo $this->render('link/header.phtml') ?>
<?php $gridId=uniqid(); ?>
//常用变量初始化

var module="site";
var gridTitle="添加链接";
var dataId="site_id";
Ext.form.Field.prototype.msgTarget = 'side';


 

//避免自动定义combo内容，重新定义一个store.                                        
var client_combo_store_link_add=new Ext.data.JsonStore({
																	  url:baseUrl+'/link/serverclient/',
																	  totalProperty: 'total',
																	  root:'results',
																	  fields:['client_id','client_company','client_host']
																	});    

var client_combo=new Ext.form.ComboBox({
										width:280,
										fieldLabel:'选择客户',
										store:client_combo_store_link_add,										
        								displayField:'client_host',
        								valueField :'client_host',
										hiddenName:"client_host",
        								typeAhead:false,
        								mode:'local',
        								triggerAction:'all',                                        
        								emptyText:'请选择...',
        								selectOnFocus:true,
                                        queryParam:'client_host',                                                   
                                        //hideTrigger: true, //隐藏下拉箭头   
										loadingText: '正在加载...',
                                        pageSize:8,
                                        minChars:1,
                                        queryDelay:300,   
                                        mode :'remote',  
                                        resizable:true, 
                                        listeners:{
                                        	select:function(){                                        	
                                        	}
                                        }
										 });                                           
 
                                                                                
var keyword_add=new Ext.FormPanel({
	frame:true,
    title:gridTitle,
    labelWidth:80,
    //width:800,
    autoWidht:true,
    autoHeight:true,
    renderTo:'grid_<?=$gridId?>',
    bodyStyle:'padding:0 0 0 0;',    
    items:[client_combo,{
    	xtype:'textfield',
        fieldLabel:'关键词',
        name:'keyword_name',
        allowBlank:false,
        width:250
        },
        {
        xtype:'fieldset',
        autoHeight:true,
        width:400,
        title:"链接属性",
        items:[{xtype:'textfield',
        		fieldLabel:'TargetPage',
                name:'keyword_link[]',
                width:250,
                vtype:'url'
        },{
        		xtype:'textarea',
                width:200,
                height:60,
            	fieldLabel:'链接说明',
                name:'keyword_link_decription[]'
        },{
        	xtype:'button',
            text:'添加',
            iconCls:'icn-add',
            handler:fieldsetAdd
        }]        
        }
    ],
    buttons:[
    {
    id:'submit',
    text:'提交',
    type:'submit',
    iconCls:'icn-control',
    handler:function(){
    if(keyword_add.getForm().isValid()){
    keyword_add.getForm().submit({
    waitTitle:'提示',
    waitMsg:'请稍等',
    url:baseUrl+'/link/serverkeyword/type/add',
    success:function(form,action){
    	var _message=Ext.util.JSON.decode(action.response.responseText);
		Ext.MessageBox.alert('提示',_message.msg,function(){
       	Ext.getCmp('content').getActiveTab().getUpdater().refresh();
        });
    },
    failure:function(form,action){
    	var _message=Ext.util.JSON.decode(action.response.responseText);
        Ext.MessageBox.alert('提示',_message.msg);
    }
    });
    }   
    }},{
    text:'退出',
    handler:function(){
    //console.dir(Ext.getCmp('content').getActiveTab().getUpdater());
    Ext.getCmp('content').remove(Ext.getCmp('content').getActiveTab());
    //Ext.getCmp('content').getActiveTab().remove();
    }
    }
    ]
});

function fieldsetAdd(){
	var MyFieldSet = new Ext.form.FieldSet({   	
	autoHeight:true,
    width:400,
    title:"链接属性",   
	items: [{xtype:'textfield',
        		fieldLabel:'链接地址',
                name:'keyword_link[]',
                width:250,
                vtype:'url'
        },{
        		xtype:'textarea',
                width:200,
                height:60,
            	fieldLabel:'链接说明',
                name:'keyword_link_decription[]'
        },{
        		xtype:'button',
                text:'移除',
                iconCls:'icn-delete',
                handler:function(){
                var f = MyFieldSet.form || MyFieldSet.getForm();
				MyFieldSet.items.each(function(item) {
			    f.remove(item);
				});
				MyFieldSet.destroy();
                }
        }
        ]   
	});  
    
    keyword_add.add(MyFieldSet); 
    keyword_add.doLayout();
    MyFieldSet.form=keyword_add.getForm();
    keyword_add.initFields.call(MyFieldSet);
    
}

});
</script>
<body style="width:98%;height:100%">
<div id='grid_<?=$gridId?>'></div>
</body>
</html>
